home *** CD-ROM | disk | FTP | other *** search
- /*
- File: ColorPenState.c
-
- Contains: Utility routines to save and restore the graphics state of a grafport.
-
- Version: Appearance 1.0 SDK
-
- Copyright: © 1997 by Apple Computer, Inc., all rights reserved.
-
- File Ownership:
-
- DRI: Edward Voas
-
- Other Contact: 7 of 9, Borg Collective
-
- Technology: OS Technologies Group
-
- Writers:
-
- (edv) Ed Voas
-
- Change History (most recent first):
-
- <1> 9/11/97 edv First checked in.
- */
-
- #include "ColorPenState.h"
- #include "ColorUtils.h"
- #include "Assertions.h"
-
- //-----------------------------------------------------------------------------------------
- // • GetColorAndPenState
- //
- // Gets the current drawing environment and stores the data in state. We copy pen and back
- // pix pats only if they are not type 0 (plain ol expanded black and white patterns).
- //-----------------------------------------------------------------------------------------
-
- void
- GetColorAndPenState( ColorPenState* state )
- {
- GrafPtr curPort;
-
- GetPort( &curPort );
-
- state->pnPixPat = NewPixPat();
- state->bkPixPat = NewPixPat();
-
- GetForeColor( &state->foreColor );
- GetBackColor( &state->backColor );
-
- GetPortPenPixPat( curPort, state->pnPixPat );
- GetPortBackPixPat( curPort, state->bkPixPat );
-
- GetPenState( &state->pen );
- state->textMode = GetPortTextMode( curPort );
- }
-
- //-----------------------------------------------------------------------------------------
- // • SetColorAndPenState
- //
- // Sets the current drawing environment based on the data in state.
- //-----------------------------------------------------------------------------------------
-
- void
- SetColorAndPenState( ColorPenState* state, Boolean dispose )
- {
- GrafPtr curPort;
-
- GetPort( &curPort );
-
- SetPenState( &state->pen );
-
- RGBForeColor( &state->foreColor );
- RGBBackColor( &state->backColor );
-
- if ( state->pnPixPat )
- SetPortPenPixPat( curPort, state->pnPixPat );
-
- if ( state->bkPixPat )
- SetPortBackPixPat( curPort, state->bkPixPat );
-
- TextMode( state->textMode );
-
- if ( dispose )
- DisposeColorAndPenState( state );
- }
-
- //-----------------------------------------------------------------------------------------
- // • DisposeColorAndPenState
- //
- // Blow away any pixpats we might have
- //-----------------------------------------------------------------------------------------
-
- void
- DisposeColorAndPenState( ColorPenState* state )
- {
- if ( state->pnPixPat )
- {
- DisposePixPat( state->pnPixPat );
- state->pnPixPat = nil;
- }
-
- if ( state->bkPixPat )
- {
- DisposePixPat( state->bkPixPat );
- state->bkPixPat = nil;
- }
- }
-
- //-----------------------------------------------------------------------------------------
- // • NormalizeColorAndPen
- //
- // Sets up our environment to standard drawing fare.
- //-----------------------------------------------------------------------------------------
-
- void
- NormalizeColorAndPen()
- {
- RGBColor black, white;
- Pattern whitePat = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- GrafPtr curPort;
-
- GetPort( &curPort );
-
- black.red = black.green = black.blue = 0x0000;
- white.red = white.green = white.blue = 0xFFFF;
-
- RGBForeColor( &black );
- RGBBackColor( &white );
-
- PenNormal();
- BackPat( &whitePat );
- TextMode( srcOr );
- }
-